#include <SDL/SDL.h>
#include <stdio.h>

int main ()
{
  SDL_Surface *screen;
  SDL_Event event;

  // Init SDL's video system.
  if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    printf("Unable to initialize SDL: %s\n", SDL_GetError());
    return 1;
  }
  
  // Call SDL_Quite when the program exists.
  atexit(SDL_Quit);

  // Set the video mode.
  screen = SDL_SetVideoMode(640, 480, 16, 0);
  if (screen == NULL) {
    printf("Unable to set video mode: %s\n", SDL_GetError());
    return 1;
  }

  // Start the event loop.
  while (SDL_WaitEvent(&event) != 0) {

    SDL_keysym keysym;
    
    // Check the event type.
    switch (event.type) {

    case SDL_KEYDOWN:

      printf("Key pressed. ");

      keysym = event.key.keysym;
      printf("SDL keysym is %i. ", keysym.sym);
      printf("(%s) ", SDL_GetKeyName(keysym.sym));

      // Left shift modifier.
      if (event.key.keysym.mod & KMOD_LSHIFT)
	printf("Left shift is down.\n");
      else
	printf("Left shift is up.\n");

      // Did the user press Q?
      if (keysym.sym == SDLK_q) {
	printf("'Q' pressed, exiting.\n");
	exit(0);
      }

      break;

    case SDL_KEYUP:

      printf("Key pressed. ");

      keysym = event.key.keysym;
      printf("SDL keysym is %i. ", keysym.sym);
      printf("(%s) ", SDL_GetKeyName(keysym.sym));

      // Left shift modifier.
      if (event.key.keysym.mod & KMOD_LSHIFT)
	printf("Left shift is down.\n");
      else
	printf("Left shift is up.\n");

      break;

      // Close window.
    case SDL_QUIT:
      
      printf("Quit event. Bye.\n");
      exit(0);
    }

  }

  return 0;
}
